#ifndef ______path_h____
#define ______path_h____

#include "stdafx.h"
//#include <list>
//#include <cassert>
//
//#include "MyCommon.h"

using namespace MyCommon;
typedef std::list<MyCommon::Vector3> PointList;
typedef MyCommon::Real MyReal;
typedef MyCommon::Vector3 MyVec3;

class Path
{
private:
	
	
	PointList m_wayPoints;
	PointList::iterator m_curWayPoint;	//points to the current waypoint

	//
	//flag to indicate if the path should be looped
	//(The last waypoint connected to the first)
	bool m_bLooped;
public:

	Path():m_bLooped(false), m_curWayPoint(m_wayPoints.end()){}

	//
	//constructor for creating a path with initial random waypoints. MinX/Y
	//& MaxX/Y define the bounding box of the path.
	Path(int NumWaypoints,
		MyReal MinX,
		MyReal MinZ,
		MyReal MaxX,
		MyReal MaxZ,
		bool looped):m_bLooped(looped)
	{
		CreateRandomPath(NumWaypoints, MinX, MinZ, MaxX, MaxZ);
		m_curWayPoint= m_wayPoints.begin();
	}

	//
	//returns the current waypoint
	MyVec3 CurrentWaypoint()const{assert(m_curWayPoint != NULL); return *m_curWayPoint;}
	//
	//returns true if the end of the list has been reached
	bool Finished(){return !(m_curWayPoint != m_wayPoints.end());}
	//
	//moves the iterator on to the next waypoint in the list
	inline void SetNextWaypoint();
	////creates a random path which is bound by rectangle described by
	//the min/max values
	PointList CreateRandomPath(int NumWaypoints,MyReal MinX,MyReal MinY,MyReal MaxX,
		MyReal MaxY);
	void LoopOn(){m_bLooped = true;}
	void LoopOff(){m_bLooped = false;}
	//
	//adds a waypoint to the end of the path
	void AddWayPoint(MyVec3 new_point);

	//methods for setting the path with either another Path or a list of vectors
	void Set(PointList new_path){m_wayPoints = new_path;m_curWayPoint = m_wayPoints.begin();}
	void Set(const Path& path){m_wayPoints=path.GetPath(); m_curWayPoint = m_wayPoints.begin();}

	void Clear(){m_wayPoints.clear();}

	PointList GetPath()const{return m_wayPoints;}


};

void Path::SetNextWaypoint()
{
	assert (m_wayPoints.size() > 0);
	if (++m_curWayPoint == m_wayPoints.end())
	{
		if (m_bLooped)
		{
			m_curWayPoint = m_wayPoints.begin(); 
		}
	}
}



#endif